package com.dhh.toodledo.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CUtil {
	public static String getDate(long timeStamp,int dateFormate){
		String formate = "MMM d, yyyy";
		if(dateFormate==0){
			formate = "MMM d, yyyy";
		}else if(dateFormate==1){
			formate = "MM/dd/yyyy";
		}if(dateFormate==2){
			formate = "dd/MM/yyyy";
		}if(dateFormate==3){
			formate = "yyyy/MM/dd";
		}		

		Long timestamp = Long.valueOf(timeStamp)*1000;  
		String date = new java.text.SimpleDateFormat(formate).format(new java.util.Date(timestamp));
		return date;
	}
	
	public static Date getDate(String format, String dateStr){
		try {
			return new java.text.SimpleDateFormat(format).parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static String getStamp(Date pDate){
		Timestamp appointTime=Timestamp.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(pDate));
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		Date date = new Date();
		try {
			date = df.parse(String.valueOf(appointTime));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		long s=date.getTime();  
		String unixDate=String.valueOf(s).substring(0, 10);
		return unixDate;
	}
	
	public static Date getDate(long timeStamp){
		Long timestamp = timeStamp*1000;  
		return new java.util.Date(timestamp);
	}
	
	
}
